﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace client35 {
	public partial class log_frm : Form {

		private string logfile_path => $"{Application.StartupPath}\\logs";

		public log_frm() {
			InitializeComponent();
			load_file();
		}

		private void load_file() {
			if (!Directory.Exists(logfile_path)) {
				MessageBox.Show($"日志文件路径:{logfile_path} 不存在");
			}

			var files = Directory.GetFiles(logfile_path, "*", SearchOption.AllDirectories);

			foreach (var file in files) {
				var item = new ListViewItem();
				item.Text = Path.GetFileNameWithoutExtension(file);
				item.Tag = file;
				this.lv_logfile.Items.Add(item);
			}
		}

		private void btn_load_Click(object sender, EventArgs e) {
			var l_listitem = this.lv_logfile.SelectedItems;
			if (l_listitem.Count <= 0) {
				MessageBox.Show("请选择文件"); return;
			}
			var file_path = l_listitem[0].Tag.ToString();
			using (var fs = new FileStream(file_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
				using (var sr = new StreamReader(fs, Encoding.GetEncoding("GB2312"))) {
					this.richTextBox1.Text = sr.ReadToEnd();
				}
			}
		}
	}
}
